package cn1shared.util;


public class StringUtil {

	private StringUtil() {} // never

	public static String trim(String value, int size) {
		if (value.length() > size)
			return value.substring(0, size) + "...";
		return value;
	}

	public static String trim(String value, char c) {
		int posStart = 0;
		while (posStart < value.length() && value.charAt(posStart) == c)
			posStart++;
		int posEnd = value.length() - 1;
		while (posEnd >= 0 && value.charAt(posEnd) == c)
			posEnd--;
		if (posEnd < posStart)
			return "";
		return value.substring(posStart, posEnd + 1);
	}

	public static String remove(String src, String piece) {
		int pos = src.indexOf(piece);
		if (pos < 0)
			return src;
		String before = src.substring(0, pos);
		int posAfter = pos + piece.length();
		String after = posAfter == src.length()? "" : src.substring(posAfter + 1);
		return before + after;
	}

}
